import Button from "components/Base/Button";
import Icon from "components/Base/Icon";
import Image from "components/Base/Image";
import DataTable from "components/Base/DataTable";
import {Spin} from "antd";
import {city, city2Level, get2Level} from "assets/const/city";


const areaColumns = [
  {
    title: 'id',
    name: 'id',
    tableItem: {},
  },
  {
    title: '区域名字',
    name: 'name',
    tableItem: {},
  },
];

export default (self) => [
  {
    title: 'id',
    name: 'id',
    formItem: {
      type: 'hidden',
    }
  },

  // {
  //   title: '医院图片',
  //   name: 'pic',
  //   tableItem: {
  //     render: (text, record) =>{
  //       return (
  //         <Image defaultIndex="3" style={{width: 30}}/>
  //       );
  //     }
  //   },
  //   formItem: {
  //     type: 'upload',
  //     listType: 'picture',
  //     maxFileSize: 1000, // 最大限制 kb
  //     fileTypes: ['.png', '.jpg', '.gif'], // 允许类型
  //     max: 1
  //   },
  // },
  {
    title: '医院名字',
    name: 'name',
    tableItem: {},
    formItem: {
      rules: [
        {
          required: true,
          message: '请输入区域名字'
        }
      ]
    },
  },
  {
    title: '区域',
    name: 'areaId',
    tableItem: {},

    formItem: {
      rules: [
        {
          required: true,
          message: '请选择区域'
        }
      ],

      showSearch: true,
      type: 'select',
      loading: self.getArea().loading,  // 加载状态
      onDropdownVisibleChange : (visible) =>{
        if (visible){
          self.dispatch({
            type: `area/getAll`,
          })
        }
      }
    },
    dict: self.getArea().dict,
  },
  {
    title: '城市',
    name: 'city',
    tableItem: {
    },
    formItem: {
      type: 'cascade',
      options: city2Level,
      rules: [
        {
          required: true,
          message: '请选择城市'
        }
      ],
    }
  },
  {
    title: '联系人',
    name: 'contact',
    tableItem: {},
    formItem: {}
  },
  {
    title: '医院地址',
    name: 'address',
    tableItem: {},
    formItem: {}
  },
  {
    title: '设备数量',
    name: 'deviceCount',
    tableItem: {},
  },

  {
    title: '操作',
    tableItem: {
      width: 180,
      align: 'center',
      render: (text, record) => {

        const {id} = record;

        var path = `/detail/hospital/${id}`;

        return (
          <DataTable.Oper>
            <Button tooltip="修改" onClick={e => self.onUpdate(record)}>
              <Icon type="edit"/>
            </Button>
            <Button tooltip="删除" onClick={e => self.onDelete(record)}>
              <Icon type="trash"/>
            </Button>
            <Button tooltip="详情" onClick={e => self.jump(path)}>
              <Icon antd={true} type="snippets"/>
            </Button>
          </DataTable.Oper>
        );
      }

    }
  }
]
